package com.sunspring.zdcall.quartz.entity;

import com.sunspring.zdcall.quartz.constant.DefaultCornExpress;

import javax.validation.constraints.NotNull;

/**
 * @author wulei
 * @date 2018-12-19
 **/
public class RegisterJobEntity extends QuartzEntity {

    /**
     * registerJob访问的数据源ID
     */
    @NotNull(message = "数据源不能为空")
    private int source;

    /**
     * 返回的数据类型 （1-db 2-json 3-xml）
     */
    private int type;

    public int getSource() {
        return source;
    }

    public void setSource(int source) {
        this.source = source;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public static RegisterJobEntity build(Integer source,Integer type) {
        return commonBuild(source,type,DefaultCornExpress.TWO_SECONDS_INTERVAL.getCorn());
    }

    public static RegisterJobEntity build(Integer source,Integer type,String cornExpress) {
        return commonBuild(source,type,cornExpress);
    }

    private static RegisterJobEntity commonBuild(Integer source,Integer type,String cornExpress) {
        if (source == null) {
            throw new NullPointerException("创建定时任务失败，数据源为空");
        }else if (type == null) {
            throw new NullPointerException("创建定时任务失败，数据返回类型为空");
        }else if (cornExpress == null) {
            throw new NullPointerException("创建定时任务失败，corn表达式为空");
        }
        RegisterJobEntity rje = new RegisterJobEntity();
        rje.setJobName("dataCollectJob-" + source);
        rje.setJobGroup("dataCollectGroup");
        rje.setTriggerName("dataCollectTrigger-" + source);
        rje.setTriggerGroup("dataCollectTriggerGroup");
        rje.setCronExpression(cornExpress);
        rje.setSource(source);
        rje.setType(type);
        rje.setDescription("获取登记信息，数据来源：" + source + "，数据类型：" + type);
        return rje;
    }
}
